package signalprocessing;



import ikelib.PlotColor;
import ikelib.wintime;

import java.awt.Rectangle;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Set;
/**
 * 
 */

/**
 * XTプロットビューのベースクラス
 * 
 * @author Toshiharu Ikeda <ikeda.104@gmail.com>
 *
 */
abstract public class PlotPaneYT extends PlotPane {


	
	public PlotPaneYT(){
		super();
	}
	
	
	/**
	 * 
	 * Polylineを計算する。
	 * @param g
	 */
	protected boolean PolyLineCalc(){
		//System.out.println("PolyCalc 1");
		if(ViewRect == null){
			ViewRect = new Rectangle(0,0,getWidth(),getHeight());
		}
		
		double yamp = (ViewRect.height-1)/2.0;
		
		double dmax = -Double.MAX_VALUE;
		double dmin = Double.MAX_VALUE;
		int vtstart = calcViewTimeStart();
		int vtspan  = calcViewTimeSpan();
		if(vtstart<=0) vtstart=0;		
		Integer[] id = getChannel();
		for(int i=0;i<id.length;i++){
			if(id[i]==null) return false;
			double d[] = getData(id[i]);
			int dlen = d.length;
			int[] datx = new int[calcViewTimeSpan()];
			int[] daty = new int[calcViewTimeSpan()];
			int didx = vtstart;
			//System.out.println("PolyCalc 3");
			for(int j=0;j<vtspan;j++,didx++){
				if(didx>=dlen) break;
				double data = d[didx];
				if(data < dmin) dmin = data;
				if(data > dmax) dmax = data;
				datx[j] = (int)((double)ViewRect.width * (double)j / (double)(vtspan-1)/* - ViewTimeStart */+ ViewRect.x);
				daty[j] = (int)(-(data-YScale.ScaleCenter)/YScale.ScaleAmp * yamp);
			}
			PolyDataX.put(id[i], datx);
			PolyDataY.put(id[i], daty);
			PolyDataLen.put(id[i], didx-vtstart);
		}
		YScale.TempDispDataMax = dmax;
		YScale.TempDispDataMin = dmin;
		return true;
	}

}
